home *** CD-ROM | disk | FTP | other *** search
- -- Partitions GCW 10/10/92
-
- -- represented as lists of integers with entries in decreasing order.
-
- type Partition = [Int]
-
- -- type declarations for values in this script.
- parts :: Int -> [Partition]
- partsTo :: Int -> Int -> [Partition]
- dual :: Partition -> Partition
- tableau :: Partition -> String
-
- -- the list of partitions of n
- parts n = partsTo n n
-
- -- partsTo n k gives list of partitions of k into pieces of size <= n.
- partsTo 0 _ = [[]] -- only the empty list
- partsTo _ 0 = [[]] -- only the empty list
- partsTo n k = [ m:ns | m <- reverse [1..min n k], ns <- partsTo m (k-m) ]
-
- -- NB. reverse reverses lists, min a b gives minimum of a and b.
- -- _ is 'wildcard', i.e. anything.
-
- -- the dual of a partition is got by interchanging rows and
- -- columns of its Young's tableau.
- dual [] = []
- dual xs = (length xs):dual [ x-1 | x <- xs, x > 1 ]
-
- length :: [a] -> Int
- length x = sum [ 1 | _ <- x ]
-
- -- Young's tableau of partition p
- tableau p = '\n':concat [ linesOfSize x | x <- reverse (dual p) ]
- where linesOfSize m = (concat (take m stars))++"\n"
- stars = " *":stars
-
- concat :: [[a]] -> [a]
- concat [] = []
- concat (x:xs) = x ++ concat xs
-
- reverse = f [] where
- f xs [] = xs
- f xs (y:ys) = f (y:xs) ys
-
- -- NB. concat concatenates a list of lists, take m gives first m items,
- -- ++ concatenates two lists, : conses an item to a list, "\n" is string
- -- consisting of a single newline, '\n' is newline character.
-
-